﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Zy.WPF.CtrLib.Ctrs
{
    /// <summary>
    /// ZyPageBar.xaml 的交互逻辑
    /// </summary>
    public partial class ZyPageBar : UserControl, INotifyPropertyChanged
    {
        /// <summary>
        /// 分页
        /// </summary>
        public ZyPageBar()
        {
            InitializeComponent();
            for(var i = 0; i < _pageCount; i++)
            {
                _pageBtns.Add(new ZyPageBtn()
                {
                    Value = i + 1,
                    Text = (i + 1).ToString(),
                });
                
            }
            this.DataContext = this;
            items.ItemsSource = _pageBtns;
        }
        #region 属性
        private List<ZyPageBtn> _pageBtns { get; set; } = new List<ZyPageBtn>();
        /// <summary>
        /// 总条数
        /// </summary>
        private int _total { get; set; } = 0;
        /// <summary>
        /// 总页数
        /// </summary>
        private int _pageCount { get; set; } = 0;
        /// <summary>
        /// 总条数
        /// </summary>
        public int Total
        {
            get { return _total; }
            set
            {
                _total = value;
                NotifyPropertyChanged("Total");
            }
        }
        /// <summary>
        /// 总页数
        /// </summary>
        public int PageCount { 
        get { return _pageCount; }
            set { 
                _pageCount = value;
                NotifyPropertyChanged("PageCount");
               
            }
        }
        private void PageBtnOnclick(int value)
        {

        }
        /// <summary>
        /// 每页个数
        /// </summary>
        private int _pageSize { get; set; } = 15;
        /// <summary>
        /// 每页个数
        /// </summary>
        public int PageSize {
            get { return _pageSize; }
            set
            {
                _pageSize=value;
                NotifyPropertyChanged("PageSize");
            }
        }
        /// <summary>
        /// 当前页
        /// </summary>
        private int _currentPage { get; set; } = 1;
        /// <summary>
        /// 当前页
        /// </summary>
        public int CurrentPage {
            get => _currentPage;
            set { 
                _currentPage = value;
                NotifyPropertyChanged("CurrentPage");
            }
        }
        #endregion
        #region INotifyPropertyChanged
        public event PropertyChangedEventHandler? PropertyChanged;
        /// <summary>
        /// 属性改变
        /// </summary>
        /// <param name="propName"></param>
        public void NotifyPropertyChanged(string propName)
        {
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(propName));
        }
        #endregion
    }
}
